package me.flyray.admin.biz;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import me.flyray.admin.vo.BaseUserSkinStyleRequest;
import me.flyray.admin.entity.BaseUserSkinStyle;
import me.flyray.admin.mapper.BaseUserSkinStyleMapper;
import org.springframework.stereotype.Service;

import me.flyray.common.biz.BaseBiz;
import me.flyray.common.msg.ResponseCode;
import me.flyray.common.util.EntityUtils;

import lombok.extern.slf4j.Slf4j;

/**
 * 用户皮肤样式
 *
 * @author centerroot
 * @email ${email}
 * @date 2018-08-31 09:19:23
 */
@Slf4j
@Service
public class BaseUserSkinStyleBiz extends BaseBiz<BaseUserSkinStyleMapper, BaseUserSkinStyle> {
	
	/**
	 * 查询用户皮肤
	 * @author centerroot
	 * @time 创建时间:2018年8月31日上午10:42:03
	 * @param baseUserSkinStyleRequest
	 * @return
	 */
	public Map<String, Object> queryObj(BaseUserSkinStyleRequest baseUserSkinStyleRequest){
		log.info("【查询用户皮肤】   请求参数：{}",EntityUtils.beanToMap(baseUserSkinStyleRequest));
		Map<String, Object> respMap = new HashMap<String, Object>();
		BaseUserSkinStyle baseUserSkinStyleReq = new BaseUserSkinStyle();
		baseUserSkinStyleReq.setPlatformId(baseUserSkinStyleRequest.getPlatformId());
		baseUserSkinStyleReq.setUserId(baseUserSkinStyleRequest.getUserId());
		
		List<BaseUserSkinStyle> baseUserSkinStyleList = mapper.select(baseUserSkinStyleReq);
		if (null != baseUserSkinStyleList && baseUserSkinStyleList.size() > 0) {
			BaseUserSkinStyle baseUserSkinStyle = baseUserSkinStyleList.get(0);
			respMap.put("baseUserSkinStyle", baseUserSkinStyle);
		}
		respMap.put("code", ResponseCode.OK.getCode());
        respMap.put("message", ResponseCode.OK.getMessage());

		log.info("【查询用户皮肤】   响应参数：{}", respMap);
		return respMap;
	}
	
	/**
	 * 添加或更新用户皮肤
	 * @author centerroot
	 * @time 创建时间:2018年8月31日上午10:41:47
	 * @param baseUserSkinStyleRequest
	 * @return
	 */
	public Map<String, Object> addOrUpdate(BaseUserSkinStyleRequest baseUserSkinStyleRequest){
		log.info("【添加或更新用户皮肤】   请求参数：{}",EntityUtils.beanToMap(baseUserSkinStyleRequest));
		Map<String, Object> respMap = new HashMap<String, Object>();
		BaseUserSkinStyle baseUserSkinStyleReq = new BaseUserSkinStyle();
		baseUserSkinStyleReq.setPlatformId(baseUserSkinStyleRequest.getPlatformId());
		baseUserSkinStyleReq.setUserId(baseUserSkinStyleRequest.getUserId());
		
		List<BaseUserSkinStyle> baseUserSkinStyleList = mapper.select(baseUserSkinStyleReq);
		if (null != baseUserSkinStyleList && baseUserSkinStyleList.size() > 0) {
			BaseUserSkinStyle baseUserSkinStyle = baseUserSkinStyleList.get(0);
			baseUserSkinStyle.setSkinStyle(baseUserSkinStyleRequest.getSkinStyle());
			baseUserSkinStyle.setUpdateTime(new Timestamp(System.currentTimeMillis()));
			mapper.updateByPrimaryKeySelective(baseUserSkinStyle);
			
		} else {
			baseUserSkinStyleReq.setSkinStyle(baseUserSkinStyleRequest.getSkinStyle());
			baseUserSkinStyleReq.setCreateTime(new Timestamp(System.currentTimeMillis()));
			mapper.insertSelective(baseUserSkinStyleReq);
		}
		respMap.put("code", ResponseCode.OK.getCode());
        respMap.put("message", ResponseCode.OK.getMessage());

		log.info("【添加或更新用户皮肤】   响应参数：{}", respMap);
		return respMap;
	}
	
}